<?php
	session_start();
	if(isset($_SESSION['username']))
	{
			if($_SESSION['logged_in']=="true")
			{
					$allow_write = 'true';
			}	else{
					$allow_write = 'false';
			}
	}
	else{
			$allow_write = 'false';
	}
	
	print_r($_SESSION);
?>
<!DOCTYPE HTML>
<html>
  <head>
    <title>Feedback</title>
        <link type = "image/x-icon" rel="SHORTCUT ICON" href="img/favicon.ico" />	
        <script type="text/javascript" src="jquery/jquery-1.8.0.min.js"></script>     
        <script type="text/javascript" src="jquery/phoneticunicode.js"></script> 
		<link rel="stylesheet" href="css/newstyle.css" />
		<link rel="stylesheet" href="css/style.css" />
        <link rel="stylesheet" href="css/grid-12.css" />
		<?php include("html/meta.html"); ?>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

        <script type="text/javascript" language="javascript">
          $('document').ready(function() {
						switchto('english');
						$('.manual-button').click(function(){
							$('#tstmnl_cntnt').focus();
							var id = $(this).attr("id");
							var myValue = $('#'+id+' .ass-text').html();
							insertAtCursor(myValue);
						});
						
						//$('#tstmnl_cntnt').phoneticeditor();
						makePhoneticEditor('tstmnl_cntnt');
						/* Phonetic editor functions */
              //var allow_write="true";
                var defaultPage=0;
                var cur=defaultPage;
                var pageLength=10;

                
                var totalPage=$(".testimonial").length/pageLength;
                totalPage=Math.ceil(totalPage);
                show(defaultPage, totalPage);
                //$('#19.testimonial').removeClass('hide');
                $('#older').click(function(){
                    if(totalPage>cur)
                        show(++cur, totalPage);
                    });                
                $('#oldest').click(function(){
                    if(totalPage>cur)
                    {
                        cur=totalPage-1;
                        show(cur,  totalPage);
                    }
                    });
                $('#newer').click(function(){
                    if(cur>0)
                        show(--cur,  totalPage);
                    });
                $('#newest').click(function(){
                        cur=0;
                        show(cur,  totalPage);
                    //$('#newer').addClass('hide');
                    //$('#newest').addClass('hide');
                        
                    });             
                if('<?php echo $allow_write; ?>' == "false")
                {
                    //add cover and instruction to sign in
                    $('#tstmnl_opq_lyr').addClass("tstmnl_cvr");
                    $('#tstmnl_opq_lyr').html('<br><br><br>Please login with <a id="signin_link_under_opaque_layer" href="google-openid/login-google.php?login&oauth_provider=google"><img src="img/google.png" height="30" style="margin-bottom: -10px;"/></a>  or <a href="login.php">My Arunchal</a> to post a feedback.');    
                }
                
                //alert("js fine!!!");
                //$('#dor').datepicker();
                $('#pst_tstmnl').click(function(){
                    validation('<?php echo $allow_write; ?>');
                    } );
                
                //delete testimonial
                $('.dlt_tstmnl').click(function(event){
                    var id=event.target.id;
                    
								confirm_popup("Are you sure you want to remove ?", id);
			});
							
});      


		function switchto(lang){
			if(lang == 'assamese'){
				switched=false;
				$('.bubble').show();
				
			}
			if(lang == 'english'){
				switched=true;
				$('.bubble').hide();
			}
		}
		function validation(allow_write	)
		{
				var error=0;
				if($('#tstmnl_cntnt').val()=='' || $('#tstmnl_cntnt').val()==' ')
				{
						error=1;
						$('#tstmnl_cntnt_error').html("feedback is empty");
				}
				if(allow_write=="false")
				{
						error=1;
				}
				if(error==0)
				{
					$.post('proc/save-feedback.php', {email: "<?php if(isset($_SESSION['email']))  echo $_SESSION['email'] ?>", name: "<?php if(isset($_SESSION['username'])) echo $_SESSION['username']; ?>", tstmnl: $('#tstmnl_cntnt').val()}, function(data){
						if(data!='false')
						{
							window.location.reload();
						}														
					});
				}
				
		}
		function show(page, total)
		{
				
				//alert("inside show"+page+total);
				$('#links').removeClass('hide');
				$('#links').addClass('hide');
				var pageLength=10;
				//var curPage=0;
				var defaultPage=0;
				$('.testimonial').removeClass('hide');
				$('.testimonial').addClass('hide');
				for(i=0;i<pageLength;i++)
				{
						$('#t_'+(page*pageLength+i)+'.testimonial').removeClass('hide');
				}
				
				if(page<total-1)
				{
						
						$('#older').removeClass('hide');
						$('#oldest').removeClass('hide');
				}
				if(page+1==total)
				{
						$('#older').removeClass('hide');
				}                
				if(page>1)
				{
						$('#newer').removeClass('hide');
						$('#newest').removeClass('hide');
				}
				if(page==1)
				{
						$('#newer').removeClass('hide');
				}               
				if(page==0)
				{
						$('#older').removeClass('hide');
						$('#oldest').removeClass('hide');
						$('#newer').addClass('hide');
						$('#newest').addClass('hide');
				}      
				if(page==total-1)
				{
						$('#newer').removeClass('hide');
						$('#newest').removeClass('hide');
						$('#older').addClass('hide');
						$('#oldest').addClass('hide');
				}
				$('#cur').html(page+1);
				$('#totalpage').html(total);
				    
				if(total<2)
				{
						$('.pageLinks').addClass('hide');
				}
				else{
						$('.pageLinks').removeClass('hide');						
				}
		}
        
		function check_login_status(){
			$.get("proc/check_login_status.php", function(data){
				alert("data");
				if(data == 'true'){
					alert("logged in");
				}
					else{
					alert("loged out");
					}
					return data;
				});
		}
	
    </script>
				
				    <style>
  .grid_9{
    width: 700px;
  }
  .testimonial{
    margin-bottom: 12px;
    padding: 4px;
    margin: 7px 0px;
  }
  .u_info{
    width: 164px;
    float: left;
    margin-right: 7px;
  }
  .u_image{
    width: 160px;
    text-align: right;
  }
  .u_name{
    width: 160px;
    font-size: 14px;
    font-weight: bold;
    text-align: right;
  }
  .u_date{
    width: 160px;
    font-size: 12px;
    font-weight: normal;
    text-align: right;
    color: #666;
  }
  .testimonial_detail{
    width: 510px;
    float: left;
    font-size: 14px;
    background-color: #FFF;
    padding: 5px;
    min-height: 92px;
  }
  
.profile_image
  {
    max-height: 50px;
    max-width: 150px;
  }
  </style>

  </head>
  <body >
    <div id="container" class="container_12">
    
    <?php
		include("inc/db.class.php");
		require("php/month.php");
		include("class/Product.class.php");
		require("php/header.php");
		include("inc/functions.php");
		$database = new database();
		$product = new Product();
		$dbo= new database();	
			
		$getBR="select * from ".DB_NAME.".tstmnl, ".DB_NAME.".users where users.id=tstmnl.USR_NMBR and tstmnl.IS_DLTD_FLG='n' order by DT_TM DESC ";
		$records=$dbo->get_records($getBR);
		$ttlTstmnl=count($records);
		$curFrame=0;	
	?>
    <div id="line" class="grid_12"></div>

			<div id="" class="grid_12">
				<h3>Feedback</h3>
				<!--facebook login starts-->
				
				<div class="grid_9">
						<div id="wrt_tstmnl_sctn_wrppr">    
								<p id="testimonial_page_description">If you have used our site and liked it, please spare a minute to share your view. If you were unhappy, write to us all the same, and tell us how we can improve. We value your feedback.</p><br />
								<p class="small_font"></p>
								<div class="u_info">
										<?php if(isset($_SESSION['usr_nmbr'])){ echo '<div class="u_image"><img class="profile_image" alt="User Image" src="img/default.jpg"/></div><div class="u_name"></div><div class="u_date">'.ymdToTextFormat2Line(date('Y-m-d H:i:s')).'</div>';} ?> 
								</div>
								<form id="tstmnlForm" action="tstmnl.php" class="floatRight" method="post">
													<script>

									</script>
									
							
										<div>
											<div class="bubble" >
												<div class="bubble-content">
													<?php include("html/letters.html"); ?>
													
												</div>
												
												<div class="bubble-arrow bubble-arrowleft" style="top: 15px; ">
													<div class="outside"></div><div class="inside"></div>
												</div>
											</div>
												<textarea id="tstmnl_cntnt" name="tstmnl" class="txt_area1"></textarea><br>
												<span id="tstmnl_cntnt_error" class="error"></span>
												<br>
												<input type="button" class="btn2 floatRight" id="pst_tstmnl"  value="Post Feedback"/>
												
												
										</div>
								</form>
								<div class="clear"></div>
								<div id="tstmnl_opq_lyr" class=""></div>
						</div>
						
						                    <div class="bld_rqrmnt_rprt">
                        <?php
                        $i=0;
                        if($ttlTstmnl>0)
                        while($ttlTstmnl>$i)
                        {                       
                            if(isset($_SESSION['usr_nmbr']))
                            {
                                if($_SESSION['usr_nmbr']==$records[$i]->USR_NMBR)
                                {                            
                                    echo '  <div id="t_'.$i.'" class="testimonial">
                                            <div class="u_info">
																								<div class="u_image"><img class="profile_image" alt="User Image" src="img/default.jpg"/></div>
																								<div class="u_name">'.$records[$i]->username.'</div>
                                                <div class="u_date">'.ymdToTextFormat2Line($records[$i]->DT_TM).'</div>
                                            </div>
                                            <div class="testimonial_detail"><img id="'.$records[$i]->TSTMNL_NMBR.'" class="dlt_tstmnl" alt="" title="Delete testimonial" width="15" height="15" src="img/close.gif"  />  '.stripslashes($records[$i]->TSTMNL).'</div>
                                            <br style="clear: both;"/>
                                        </div>';
                                }
                                else
                                {
                                    echo '  <div id="t_'.$i.'" class="testimonial">
                                            <div class="u_info">
																								<div class="u_image"><img class="profile_image" alt="User Image" src="img/default.jpg"/></div>
																								<div class="u_name">'.$records[$i]->username.'</div>
                                                <div class="u_date">'.ymdToTextFormat2Line($records[$i]->DT_TM).'</div>
                                            </div>
                                            <div class="testimonial_detail">'.$records[$i]->TSTMNL.'</div>
                                            <br style="clear: both;"/>
                                        </div>';
                                }
                            }
                            else
                            echo    '<div id="t_'.$i.'" class="testimonial">
                                    <div class="u_info">
																				<div class="u_image"><img class="profile_image" alt="User Image" src="img/default.jpg"/></div>
																				<div class="u_name">'.$records[$i]->username.'</div>
                                        <div class="u_date">'.ymdToTextFormat2Line($records[$i]->DT_TM).'</div>
                                    </div>
                                    <div class="testimonial_detail">'.$records[$i]->TSTMNL.'</div>
                                    <br style="clear: both;"/>
                                </div>';                            
                            $i++;
                        }
                        ?>
                    </div>
						        <div class="pageLinks">
                      Showing Page &nbsp <span id='cur'>1</span> of &nbsp<span id='totalpage'>1</span>  <a id='newest' class='links hide' href='#'>Newest</a><a id='newer' class='links hide' href='#'>Newer</a><a id='older' class='links hide' href='#'>Older</a><a id='oldest' class='links hide' href='#'>Oldest</a>
                    </div>



						
						
			</div>
						
			<?php require("php/footer.php"); ?>
    </div>
			<script>
				makePhoneticEditor('tstmnl_cntnt'); //pass the textarea Id
			</script>
  </body>
</html>
